const tokens = {
  admin: {
    token: "admin-token"
  },
  editor: {
    token: "editor-token"
  }
}
const users = {
  "admin-token": {
    id: 1,
    role_id: 1,
    // introduction: "I am a super administrator",
    // avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
    name: "Super Admin"
  },
  "editor-token": {
    id: 2,
    role_id: 2,
    // introduction: "I am an editor",
    // avatar: "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
    name: "Normal Editor"
  }
}

module.exports = [
  {
    url: "/login",
    type: "post",
    response: config => {
      const { username } = config.body
      const token = tokens[username]
      // mock error
      if (!token) {
        return {
          code: 60204,
          message: "Account and password are incorrect."
        }
      }

      return {
        code: 20000,
        data: tokens["admin"]
      }
    }
  },
  {
    url: RegExp("/getInfo" + '.*'),
    type: "get",
    response: config => {
    //   const query = param2Obj(config.url, token)
      const { token } = config.query
      const info = users[token]
      if (!info) {
        return {
          code: 60204,
          message: "Account and password are incorrect."
        }
      }
      return {
        code: 20000,
        data: info
      }
    }
  }, {
    url: '/outlogin',
    type: 'post',
    response: () => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  }
]
